import ajax from '../utils/ajax'
import api from '../config/api.js'

import { globalData } from '../config/globalData'
import baseUrl from '../baseUrl'

export default class Me {
  /**
   * 获取购物车商品
   */
  static async getCartGoods () {
    let url = baseUrl.server + api.GET_CART_GOODS
    let res = await ajax.post(url, {
      token: globalData.access_token
    })
    return res
  }

  /**
   * 添加商品到购物车
   */
  static async addCartGoods (goods_sku, goods_number) {
    let param = {
      token: globalData.access_token,
      goods_sku: goods_sku,
      goods_number: goods_number
    }
    let url = baseUrl.server + api.ADD_CART_GOODS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 编辑商品到购物车
   */
  static async editCartGoods (param) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.EDIT_CART_GOODS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 编辑商品到购物车
   */
  static async delCartGoods (cart_ids = []) {
    let param = {
      token: globalData.access_token,
      cart_ids: JSON.stringify(cart_ids)
    }
    let url = baseUrl.server + api.DEL_CART_GOODS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 删除购物车商品
   */
  static async delCartProducts (cart_ids = []) {
    let param = {
      token: globalData.access_token,
      cart_ids: JSON.stringify(cart_ids)
    }
    let url = baseUrl.server + api.DEL_CART_PRODUCT

    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取内购订单列表
   */
  static async getInPurchasingOrders (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_IN_PURCHASING_ORDERS
    // let res = await ajax.post(url, param)
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 获取内购待评价商品列表
   */
  static async getToBeEvaluatedOrders (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_To_Be_Evaluated_ORDERS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 评论提交
   */
  static async submitComment (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.Submit_Comment
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取内购订单详情
   */
  static async getInPurchasingOrderInfo (param) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_IN_PURCHASING_ORDER_INFO
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 取消内购订单检查
   */
  static async cancelInPurchasingOrderVerify (order_id = '') {
    let param = {
      token: globalData.access_token,
      order_id: order_id
    }
    let url = baseUrl.server + api.CANCEL_IN_PURCHASING_ORDER_VERIFY
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 取消内购订单
   */
  static async cancelInPurchasingOrder (param = {}) {
    let defParam = {
      token: globalData.access_token,
      order_id: '',
      reason_id: '',
      remark: ''
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.CANCEL_IN_PURCHASING_ORDER
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取我的佣金信息
   */
  static async getGeneralizeInfo (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_GENERALIZE_INFO
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 我的佣金提现
   */
  static async generalizeWithdraw () {
    let url = baseUrl.server + api.GENERALIZE_WITHDRAW
    let res = await ajax.post(url, {
      token: globalData.access_token
    })
    return res
  }

  /**
   * 获取我的佣金信息
   *
   */
  static async getMeDistribuionProductList (param = {}) {
    let defParam = {
      token: globalData.access_token,
      page: 1
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_ME_DISTRIBUTION_PRODUCT_LIST
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取我的地址列表
   *
   */
  static async getMeAddressList () {
    let url = baseUrl.server + api.GET_ME_ADDRESS_LIST
    let res = await ajax.post(url, {
      token: globalData.access_token
    })
    return res
  }

  /**
   * 获取区域列表
   *
   */
  static async getAreaList (param) {
    let url = baseUrl.server + api.GET_AREA_LIST
    let defParam = {
      parent_id: 0,
      deep: 0,
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let res = await ajax.post(url, param)
    if (res.code == 0) {
      let data = []
      for (var i in res.data) {
        data.push(res.data[i])
      }
      res.data = data
    }
    return res
  }

  /**
   * 添加收货地址
   *
   */
  static async addMeAddress (param) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.ADD_ME_ADDRESS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 修改收货地址
   *
   */
  static async editMeAddress (param) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.EDIT_ME_ADDRESS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 删除收货地址
   *
   */
  static async removeMeAddress (id) {
    let param = {
      token: globalData.access_token,
      address_id: id
    }

    let url = baseUrl.server + api.REMOVE_ME_ADDRESS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取开票信息列表
   *
   */
  static async getIssueInfo (type = 2) {
    let param = {
      token: globalData.access_token,
      type: type
    }

    let url = baseUrl.server + api.GET_ISSUE_LIST
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 添加开票信息
   * param
   */
  static async addIssueInfo (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)

    let url = baseUrl.server + api.ADD_ISSUE_INFO
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 修改开票信息
   * param
   */
  static async editIssueInfo (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)

    let url = baseUrl.server + api.EDIT_ISSUE_INFO
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 删除开票信息
   * param
   */
  static async removeIssueInfo (id) {
    let param = {
      token: globalData.access_token,
      id: id
    }

    let url = baseUrl.server + api.REMOVE_ISSUE_INFO
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取我的优惠券列表
   * param
   */
  static async getDiscountList (status = 1) {
    let param = {
      token: globalData.access_token,
      status: status
    }

    let url = baseUrl.server + api.GET_ME_DISCOUNT_LIST
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取售后订单类型
   *param
   */
  static async getOrderAfterType (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.GET_MALL_ORDER_AFTER_TYPE
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取售后订单申请
   *param
   */
  static async MallOrderAfterApply (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_ORDER_AFTER_APPLY
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取售后订单申请
   *param
   */
  static async mallOrderAfterCancel (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_ORDER_AFTER_CANCEL
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取售后订单列表
   *param
   */
  static async getMallOrderAfterList (param = {}) {
    let defParam = {
      token: globalData.access_token,
      sub_order_type: 1
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_ORDER_AFTER_LIST + `?page=${param.page}`
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取售后订单详情
   *param
   */
  static async getMallOrderAfterInfo (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_ORDER_AFTER_INFO
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取售后订单发货
   *param
   */
  static async mallOrderAfterSendGoods (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_ORDER_AFTER_SENDGOODS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取苏宁售后订单发货
   *param
   */
  static async mallOrderAfterSendGoodsSuNing (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_ORDER_AFTER_SENDGOODS_SUNING
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取售后订单发货
   *param
   */
  static async mallOrderAfterPutGoods (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_ORDER_AFTER_PUTDGOODS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 自营订单确认收货
   *param
   */
  static async mallZyOrderConfirmExp (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_ZY_ORDER_CONFIRM_EXP
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 自营订单确认收货
   *param
   */
  static async mallYxOrderConfirmExp (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.MALL_YX_ORDER_CONFIRM_EXP
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取售后订单申请图片上传
   *param
   */
  static async MallOrderAfterApplyImageUpload (files = []) {
    let formData = new FormData()
    files.map((file) => {
      formData.append('file', file)
    })
    formData.append('token', globalData.access_token)
    let url = baseUrl.server + api.MALL_ORDER_AFTER_APPLY_IMAGE_UPLOAD
    let res = await ajax.formPost(url, formData)
    return res
  }

  /**
   * 修改密码
   *param
   */
  static async MallChangePass (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.CHANGE_PASS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 物流信息
   *param
   */
  static async getOrderTrick (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.ORDER_TRICK
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 默认地址
   *param
   */
  static async setDefaultAddress (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.SET_DEFAULT_ADDRESS
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 京东确认收货
   */
  static async confirmJdOrder (params) {
    let param = Object.assign({}, { token: globalData.access_token, ...params })
    let url = baseUrl.server + api.CONFIRM_JD_ORDER
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 苏宁确认收货
   */
  static async confirmSnOrder (params) {
    let param = Object.assign({}, { token: globalData.access_token, ...params })
    let url = baseUrl.server + api.CONFIRM_SN_ORDER
    let res = await ajax.post(url, param)
    return res
  }

  /**
   * 获取个人信息
   */
  static async getPersonInfo () {
    let param = {
      token: globalData.access_token
    }
    let url = baseUrl.server + api.PERSON_INFO
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 更改生日
   */
  static async changeBirthday (param) {
    let params = Object.assign({}, { token: globalData.access_token }, param)
    let url = baseUrl.server + api.PERSON_INFO
    let res = await ajax.post(url, params)
    return res
  }

  /**
   * 获取额度管理列表
   */
  static async getQuotalList (param) {
    let params = Object.assign({}, { token: globalData.access_token }, param)
    let url = baseUrl.server + api.GET_QUOTA + `?page=${params.page}`
    let res = await ajax.post(url, params)
    return res
  }

  /**
   * 获取额度明细列表
   */
  static async getQuotaDetailList (param) {
    let params = Object.assign({}, { token: globalData.access_token }, param)
    let url = baseUrl.server + api.GET_QUOTA_DETAIL + `?page=${params.page}`
    let res = await ajax.post(url, params)
    return res
  }

  /**
   * 删除订单
   */
  static async deleteOrder (param) {
    let params = Object.assign({}, { token: globalData.access_token }, param)
    let url = baseUrl.server + api.DELETE_ORDER
    let res = await ajax.post(url, params)
    return res
  }

  /**
   * 获取发票信息
   */
  static async getInvoiceInfo (param) {
    let params = Object.assign({}, { token: globalData.access_token }, param)
    let url = baseUrl.server + api.GET_INVOICE_INFO
    let res = await ajax.get(url, params)
    return res
  }

  /**
   * 下载发票信息
   */
  static downloadInvoice (param) {
    // let params = Object.assign({}, { token: globalData.access_token }, param)
    let url = baseUrl.server + api.DOWNLOAD_INVOICE + `?token=${globalData.access_token}&request_order_sn=${param.request_order_sn}`
    // let res = await ajax.get(url, params)
    return url
  }

  /**
   * 自营物流信息
   *param
   */
  static async getOrderTrickZY (param = {}) {
    let defParam = {
      token: globalData.access_token
    }
    param = Object.assign(defParam, param)
    let url = baseUrl.server + api.ORDER_TRICK_ZY
    let res = await ajax.get(url, param)
    return res
  }

  /**
   * 发票发送到邮箱
   */
  static async sendEmail (param) {
    let params = Object.assign({}, { token: globalData.access_token }, param)
    let url = baseUrl.server + api.SEND_EMAIL
    let res = await ajax.post(url, params)
    return res
  }

  /**
   * 满足条件触发开票
   */
  static async askInvoice (param) {
    let params = Object.assign({}, { token: globalData.access_token }, param)
    let url = baseUrl.server + api.ASK_INVOICE
    let res = await ajax.get(url, params)
    return res
  }
}
